/*
 * Node.h
 *
 *  Created on: 14.04.2010
 *      Author: king
 */

#ifndef NODE_H_
#define NODE_H_

#include <QApplication>
#include <QColor>
#include <QGraphicsItem>
#include <QSet>

#include "genealogy_tree/Person.h"

namespace etu {
namespace ui {

class CLink;

using etu::genealogy_tree::Person;

class CNode : public QGraphicsPixmapItem
{
    Q_DECLARE_TR_FUNCTIONS(CNode)

public:

    CNode(Person* person);
    ~CNode();

    QString text() const;

    void setTextColor(const QColor &color);
    QColor textColor() const;

    void setPerson(Person* person);
    void setupPersonName();
    Person* getPerson();

    void setOutlineColor(const QColor &color);
    QColor outlineColor() const;
    void setBackgroundColor(const QColor &color);
    QColor backgroundColor() const;

    void addLink(CLink *link);
    void removeLink(CLink *link);

    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter,
               const QStyleOptionGraphicsItem *option, QWidget *widget);

    void setPhoto(QPixmap* pixmap);
    QPixmap* getPhoto();

protected:
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
    QVariant itemChange(GraphicsItemChange change,
                        const QVariant &value);

private:
    QRectF outlineRect() const;
    QRectF outlineTextRect() const;
    int roundness(double size) const;
    void trackNodes();

    QSet<CLink *> m_links;
    QString m_text;
    QColor m_textColor;
    QColor m_backgroundColor;
    QColor m_outlineColor;
    Person* m_person;
    QPixmap m_scaledPixmap;
    QPixmap* m_pixmap;
};

}
}

#endif /* NODE_H_ */
